﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualTournaments.Business.Users;
using VirtualTournaments.Business.Observer;

namespace VirtualTournaments.Business.Bets
{
	/// <summary>
	/// Representa a un resultado posible de una competicion al que se le puede apostar
	/// </summary>
	public abstract class BetTarget : Observer.ISubject
	{
		
		IList<Bet> _bets;

		/// <summary>
		/// Lo que paga acertar a este resultado
		/// </summary>
		public decimal Odds { get; protected set; }
		internal void SetOdds(decimal value) { this.Odds = value; }

		public virtual IList<Bet> Bets
		{
			get { return _bets; }
			protected set { _bets = value; }
		}

		public BetTarget()
		{
			this._bets = new List<Bet>();
		}

		/// <summary>
		/// Indica si el resultado esperado ocurrió o no
		/// </summary>
		/// <returns></returns>
		public abstract bool Occurs();

		public void AddBet(Bet bet)
		{
			this.Bets.Add(bet);
			this.Notify();
		}

		#region ISubject Members

		private Subject _subject = new Observer.Subject();

		public void AddObserver(VirtualTournaments.Business.Observer.IObserver observer)
		{
			_subject.AddObserver(observer);
		}

		public void RemoveObserver(VirtualTournaments.Business.Observer.IObserver observer)
		{
			_subject.RemoveObserver(observer);
		}

		public void Notify()
		{
			_subject.Notify();
		}

		#endregion
	}
}
